public class CDeck
{
	public enum enum_TypeOfDeck
	{
		TOD_MAJOR, TOD_HAND;
	}
	
	public enum enum_SetOfCards
	{
		SOC_NULL(0), SOC_HIGH_CARD(1), SOC_HIGH_CARD_NEAR_STRAIGHT(1), SOC_HIGH_CARD_NEAR_STRAIGHT_FLUSH(1), SOC_ONE_PAIR(2), SOC_TWO_PAIR(3),
		SOC_THREE_OF_A_KIND(4), SOC_STRAIGHT(5), SOC_FLUSH(6), SOC_FULL_HOUSE(7), SOC_FOUR_OF_A_CARD(8), SOC_STRAIGHT_FLUSH(9); 
		
		private int int_ValueOfSet;
		private enum_SetOfCards(int int_ValueOfSet)
		{
			this.int_ValueOfSet = int_ValueOfSet;
		}
	}
	
	public enum enum_ResultOfComparison
	{
		ROC_FEWER, ROC_EQUAL , ROC_LARGER;
	}
	
	class CSequence
	{
		public enum_SetOfCards soc_SetOfCards;
		public CDeck deck_SetOfCards;
		
		public CSequence()
		{
			deck_SetOfCards = new CDeck(new CCard(), new CCard(), new CCard(), new CCard(), new CCard(), false);
			soc_SetOfCards = enum_SetOfCards.SOC_NULL;
		}
		
		public CSequence(boolean bool_SortSequence)
		{
			deck_SetOfCards = new CDeck(new CCard(), new CCard(), new CCard(), new CCard(), new CCard(), bool_SortSequence);
			soc_SetOfCards = enum_SetOfCards.SOC_NULL;
		}
	}
	
	public static enum_ResultOfComparison ComparisonSequence(CSequence seq_First, CSequence seq_Second)
	{
		if(seq_First.soc_SetOfCards.int_ValueOfSet > seq_Second.soc_SetOfCards.int_ValueOfSet)
		{
			return CDeck.enum_ResultOfComparison.ROC_LARGER;
		}
		
		if(seq_First.soc_SetOfCards.int_ValueOfSet < seq_Second.soc_SetOfCards.int_ValueOfSet)
		{
			return CDeck.enum_ResultOfComparison.ROC_FEWER;
		}
		
		for(int i=0;i<5;++i)
		{	
			if(seq_First.deck_SetOfCards.getCardFromDeck(i).getIntegerValueOfCard() >
			   seq_Second.deck_SetOfCards.getCardFromDeck(i).getIntegerValueOfCard())
			   {return CDeck.enum_ResultOfComparison.ROC_LARGER;}
			
			if(seq_First.deck_SetOfCards.getCardFromDeck(i).getIntegerValueOfCard() <
			   seq_Second.deck_SetOfCards.getCardFromDeck(i).getIntegerValueOfCard())
			   {return CDeck.enum_ResultOfComparison.ROC_FEWER;}
		}
		return CDeck.enum_ResultOfComparison.ROC_EQUAL;
	}
	
	private CCard[] card_ArrayOfMajorDeck = new CCard[52];
	private CCard[] card_ArrayOfHandDeck = new CCard[5];
	
	private enum_TypeOfDeck tod_WhichDeck;
	private CCard.enum_ColorOfCard coc_Support;
	private CCard.enum_ValueOfCard voc_Support;
	private int int_WhichCardOnStack;
	
	public CDeck()
	{	
		tod_WhichDeck = enum_TypeOfDeck.TOD_MAJOR;
		int_WhichCardOnStack = 0;
		for(int i=0; i<4; ++i)
		{
			switch(i)
			{
				case 0: coc_Support = CCard.enum_ColorOfCard.COC_CLUB;
				break;
				case 1: coc_Support = CCard.enum_ColorOfCard.COC_DIAMOUND;
				break;
				case 2: coc_Support = CCard.enum_ColorOfCard.COC_HEART;
				break;
				case 3: coc_Support = CCard.enum_ColorOfCard.COC_SPADE;
				break;
			}
				
			for(int j=0; j<13;++j)
			{
				switch(j)
				{
					case 0: voc_Support = CCard.enum_ValueOfCard.VOC_TWO;
					break;
					case 1: voc_Support = CCard.enum_ValueOfCard.VOC_THREE;
					break;
					case 2: voc_Support = CCard.enum_ValueOfCard.VOC_FOUR;
					break;
					case 3: voc_Support = CCard.enum_ValueOfCard.VOC_FIVE;
					break;
					case 4: voc_Support = CCard.enum_ValueOfCard.VOC_SIX;
					break;
					case 5: voc_Support = CCard.enum_ValueOfCard.VOC_SEVEN;
					break;
					case 6: voc_Support = CCard.enum_ValueOfCard.VOC_EIGHT;
					break;
					case 7: voc_Support = CCard.enum_ValueOfCard.VOC_NINE;
					break;
					case 8: voc_Support = CCard.enum_ValueOfCard.VOC_TEN;
					break;
					case 9: voc_Support = CCard.enum_ValueOfCard.VOC_JACK;
					break;
					case 10: voc_Support = CCard.enum_ValueOfCard.VOC_QUEEN;
					break;
					case 11: voc_Support = CCard.enum_ValueOfCard.VOC_KING;
					break;
					case 12: voc_Support = CCard.enum_ValueOfCard.VOC_ACE;
					break;
				}
				card_ArrayOfMajorDeck[(i+1)*(j+1)-1] = new CCard(coc_Support,voc_Support);
			}
		}
	}
	
	public CDeck(CCard card_FirstToCreate, CCard card_SecondToCreate, CCard card_ThirdToCreate, CCard card_FourthToCreate, CCard card_FifthToCreate, boolean bool_Sort)
	{
		tod_WhichDeck = enum_TypeOfDeck.TOD_HAND;
		
		card_ArrayOfHandDeck[0] = new CCard();
		card_ArrayOfHandDeck[0] = card_FirstToCreate;
		card_ArrayOfHandDeck[1] = new CCard();
		card_ArrayOfHandDeck[1] = card_SecondToCreate;
		card_ArrayOfHandDeck[2] = new CCard();
		card_ArrayOfHandDeck[2] = card_ThirdToCreate;
		card_ArrayOfHandDeck[3] = new CCard();
		card_ArrayOfHandDeck[3] = card_FourthToCreate;
		card_ArrayOfHandDeck[4] = new CCard();
		card_ArrayOfHandDeck[4] = card_FifthToCreate;
		
		if(bool_Sort){CQuick.quicksort(card_ArrayOfHandDeck, 0, 4);}
	}
	
	public CCard getCardFromDeck(int int_WhichCard)
	{
		if(tod_WhichDeck == enum_TypeOfDeck.TOD_MAJOR) if(int_WhichCard>=0 && int_WhichCard<52) {return card_ArrayOfMajorDeck[int_WhichCard];}
		if(tod_WhichDeck == enum_TypeOfDeck.TOD_HAND)  if(int_WhichCard>=0 && int_WhichCard<5)  {return card_ArrayOfHandDeck[int_WhichCard];}
		return new CCard();
	}
	
	public void setCardFromDeck(CCard card_NewCard,int int_WhichCard)
	{
		if(tod_WhichDeck == enum_TypeOfDeck.TOD_MAJOR) if(int_WhichCard>=0 && int_WhichCard<52) {card_ArrayOfMajorDeck[int_WhichCard] = card_NewCard;}
		if(tod_WhichDeck == enum_TypeOfDeck.TOD_HAND)  if(int_WhichCard>=0 && int_WhichCard<5)  {card_ArrayOfHandDeck[int_WhichCard]  = card_NewCard;}
	}
	
	public CCard[] getDeck()
	{
		if(tod_WhichDeck == enum_TypeOfDeck.TOD_MAJOR){return card_ArrayOfMajorDeck;}
		if(tod_WhichDeck== enum_TypeOfDeck.TOD_HAND){return card_ArrayOfHandDeck;}
		return null;
	}
	
	public void setDeck(CCard[] card_NewDeck)
	{
		if(tod_WhichDeck == enum_TypeOfDeck.TOD_MAJOR){card_ArrayOfMajorDeck = card_NewDeck;}
		if(tod_WhichDeck== enum_TypeOfDeck.TOD_HAND){card_ArrayOfHandDeck = card_NewDeck;}
	}
	
	private CSequence CreateSequenceSupport(CCard[] card_Input)
	{
		int int_Pointer = 0;
		int int_Index = 0;
		
		CSequence seg_Support = new CSequence();
		
		for(int i=4;i>=1;--i)
		{	
			for(int j=0;j<4;++j)
			{
				if(card_Input[j].getIntegerValueOfCard()!=card_Input[j+1].getIntegerValueOfCard() || j==3)
				{	
					if(card_Input[j].getIntegerValueOfCard()==card_Input[j+1].getIntegerValueOfCard()){++j;}
					
					if(j-int_Pointer+1==i)
					{
						if(i==4){seg_Support.soc_SetOfCards = CDeck.enum_SetOfCards.SOC_FOUR_OF_A_CARD;}
						else if(i==3){seg_Support.soc_SetOfCards = CDeck.enum_SetOfCards.SOC_THREE_OF_A_KIND;}
						else if(i==2 && seg_Support.soc_SetOfCards == CDeck.enum_SetOfCards.SOC_THREE_OF_A_KIND)
						{seg_Support.soc_SetOfCards = CDeck.enum_SetOfCards.SOC_FULL_HOUSE;}
						else if(i==2 && seg_Support.soc_SetOfCards == CDeck.enum_SetOfCards.SOC_ONE_PAIR)
						{seg_Support.soc_SetOfCards = CDeck.enum_SetOfCards.SOC_TWO_PAIR;}
						else if(i==2){seg_Support.soc_SetOfCards = CDeck.enum_SetOfCards.SOC_ONE_PAIR;}
						for(int k=0;k<i;++k)
						{
							seg_Support.deck_SetOfCards.card_ArrayOfHandDeck[int_Index]= card_Input[int_Pointer+k];
							//System.out.println(seg_Support.deck_SetOfCards.card_ArrayOfHandDeck[int_Index].getValueOfCardName());
							++int_Index;
						}
					}
					int_Pointer = j+1;
				}
			}
			int_Pointer = 0;
		}
		//System.out.println(seg_Support.deck_SetOfCards.card_ArrayOfHandDeck[0].getValueOfCardName());
		return seg_Support;
	}
	
	public CSequence  getSequenceOfCards()
	{
		CSequence seg_Result = new CSequence();
		seg_Result.soc_SetOfCards = CDeck.enum_SetOfCards.SOC_HIGH_CARD;
		
		if(tod_WhichDeck==enum_TypeOfDeck.TOD_HAND)
		{	
			boolean bool_IdenticalColor = true;
			CCard[] card_Support = new CCard[5];
			card_Support[0]= new CCard();
			card_Support[0]=card_ArrayOfHandDeck[0];
			
			for(int i=4;i>0;--i)
			{
				if(card_ArrayOfHandDeck[i].getIntegerValueOfCard() == (card_ArrayOfHandDeck[i-1].getIntegerValueOfCard()-1))
				{
					if(card_ArrayOfHandDeck[i].getColorOfCard()!=card_ArrayOfHandDeck[i-1].getColorOfCard()){bool_IdenticalColor = false;}
				}
				else{break;}
				
				if(i==1 && bool_IdenticalColor)
				{
					seg_Result.soc_SetOfCards=CDeck.enum_SetOfCards.SOC_STRAIGHT_FLUSH;
				}
				else if(i==1)
				{
					seg_Result.soc_SetOfCards=CDeck.enum_SetOfCards.SOC_STRAIGHT;
				}
				else if(i<3 && bool_IdenticalColor){seg_Result.soc_SetOfCards=CDeck.enum_SetOfCards.SOC_HIGH_CARD_NEAR_STRAIGHT_FLUSH;}
				else if(i<3){seg_Result.soc_SetOfCards=CDeck.enum_SetOfCards.SOC_HIGH_CARD_NEAR_STRAIGHT;}
			}
			if(seg_Result.soc_SetOfCards == CDeck.enum_SetOfCards.SOC_HIGH_CARD){seg_Result = CreateSequenceSupport(card_ArrayOfHandDeck);}
		}
		//System.out.println(seg_Result.deck_SetOfCards.card_ArrayOfHandDeck[0].getIntegerValueOfCard());
		return seg_Result;
	}
}